package org.scirp.ijmis.service.common.impl;

import java.util.List;

import org.scirp.ijmis.dao.common.ISurveyChoiceDAO;
import org.scirp.ijmis.dao.common.ISurveyDAO;
import org.scirp.ijmis.po.common.Survey;
import org.scirp.ijmis.service.common.ISurveyService;

public class SurveyServiceImpl implements ISurveyService {
	private ISurveyDAO surveyDAO;
	private ISurveyChoiceDAO surveyChoiceDAO;
	@Override
	public List<Survey> selectAll() {
		return surveyDAO.selectAll();
	}

	@Override
	public Survey selectById(Object id) {
		return surveyDAO.selectById(id);
	}

	@Override
	public List<Survey> selectByPersonId(Long personId) {
		return surveyDAO.selectByPersonId(personId);
	}

	public List<Survey> selectDisplayAll() {
		return surveyDAO.selectDisplayAll();
	}
	@Override
	public Survey deleteSurvey(Survey survey) {
		return surveyDAO.deleteSurvey(survey);
	}
	@Override
	public boolean deleteSurveyBySurveyId(Long surveyId) {
		boolean flag=surveyChoiceDAO.deleteSurveyChoiceBySurveyId(surveyId);
		return flag&&surveyDAO.deleteSurveyBySurveyId(surveyId);
	}
	@Override
	public boolean updateSurvey(Survey survey) {
		return surveyDAO.updateSurvey(survey);
	}
	
	public boolean saveSurvey(List<Survey> surveys){
		boolean flag=true;
		for (Survey survey : surveys) {
			if(!surveyDAO.updateSurvey(survey)){
				flag=false;
			}
		}
		return flag;
	}
	
	
	public ISurveyDAO getSurveyDAO() {
		return surveyDAO;
	}

	public void setSurveyDAO(ISurveyDAO surveyDAO) {
		this.surveyDAO = surveyDAO;
	}

	public ISurveyChoiceDAO getSurveyChoiceDAO() {
		return surveyChoiceDAO;
	}

	public void setSurveyChoiceDAO(ISurveyChoiceDAO surveyChoiceDAO) {
		this.surveyChoiceDAO = surveyChoiceDAO;
	}

}
